stock identifier. Scripts must contain code to append run to stock if present.Data is now stored in object called AK-WCoast-Salmon-SR.csv
dat <- read.csv("AK-WCoast-Salmon-SR.csv", header=TRUE)What is the structure of this data frame?
kable(head(dat), align="crr") %>% #, digits=c(3,1,1)) %>%
kable_styling(bootstrap_options = c("striped", "hover"))| stock.id | species | run | stock | region | sub.region | broodYr | spawn | rec | large.region |
|---|---|---|---|---|---|---|---|---|---|
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1980 | 238038 | 545500 | BS |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1981 | 214728 | 318386 | BS |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1982 | 104503 | 280870 | BS |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1983 | 172143 | 319246 | BS |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1984 | 108151 | 503626 | BS |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1985 | 170739 | 939836 | BS |
Recorded brood years run from 1922 to 2016.
First we need to add recruits-per-spawner and log recruits-per-spawner
dat$rps <- dat$rec/dat$spawn
dat$ln.rps <- log(dat$rps)
kable(head(dat), align="crr") %>% #, digits=c(3,1,1)) %>%
kable_styling(bootstrap_options = c("striped", "hover"))| stock.id | species | run | stock | region | sub.region | broodYr | spawn | rec | large.region | rps | ln.rps |
|---|---|---|---|---|---|---|---|---|---|---|---|
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1980 | 238038 | 545500 | BS | 2.291651 | 0.8292725 |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1981 | 214728 | 318386 | BS | 1.482741 | 0.3938924 |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1982 | 104503 | 280870 | BS | 2.687674 | 0.9886761 |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1983 | 172143 | 319246 | BS | 1.854540 | 0.6176364 |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1984 | 108151 | 503626 | BS | 4.656693 | 1.5383055 |
| NA | Sockeye | NA | Bear | AK Peninsula | AK Peninsula | 1985 | 170739 | 939836 | BS | 5.504519 | 1.7055693 |
We also need to screen out non-sensical values reported in the data, specifically:
NA, i.e. either rec or spawn was blankWe also filter filter brood years:
broodYr > 1950 as this is the start of the NPGO index.broodYr <= 2010 to ensure all complete return of age classes for all species.
dat.2 <- dat %>% filter(!is.infinite(ln.rps), !is.na(ln.rps), broodYr>=1950, broodYr<=2010)So, the total number of observations is: 8549.
I noticed that on the West Coast there were multiple Chinook salmon run identifiers for the same stock by broodYr combination. We need to identify these instances and update the stock name so it is treated separately in subsequent data exploration and STAN stock-recruitment models.
As it turns out there are 2583 observations (years) our of 8549 for which a run is identified.
sum.stocks_species.region <- dat.2 %>% group_by(species, region) %>% summarize('n.stocks'=length(unique(stock)))
# kable(sum.stocks_species.region, align="crr") %>% #, digits=c(3,1,1)) %>%
# kable_styling(bootstrap_options = c("striped", "hover"))
g <- ggplot(sum.stocks_species.region, aes(x=region, y=n.stocks, fill=species)) +
theme_linedraw() +
scale_fill_colorblind() +
geom_bar(stat='identity', position='stack') +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ylab('Number of Stocks')
plot(g)sum.years_species.region <- dat.2 %>% group_by(species, region) %>% summarize('n.years'=n())
# kable(sum.years_species.region, align="crr") %>% #, digits=c(3,1,1)) %>%
# kable_styling(bootstrap_options = c("striped", "hover"))
g <- ggplot(sum.years_species.region, aes(x=region, y=n.years, fill=species)) +
theme_linedraw() +
scale_fill_colorblind() +
geom_bar(stat='identity', position='stack') +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
ylab('Number of Years with Data')
plot(g)## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'